<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="据点（cmt_xcbzId）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inatsite">
              <a-input v-model="model.inatsite" placeholder="请输入据点（cmt_xcbzId）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="料件编号（cmt_xcbz003）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inat001">
              <a-input v-model="model.inat001" placeholder="请输入料件编号（cmt_xcbz003）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="库存管理特征（cmt_xcbz005）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inat003">
              <a-input v-model="model.inat003" placeholder="请输入库存管理特征（cmt_xcbz005）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="HUB仓代码（cmt_xcbz006）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inat004">
              <a-input v-model="model.inat004" placeholder="请输入HUB仓代码（cmt_xcbz006）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="批号（cmt_xcbz008）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inat006">
              <a-input v-model="model.inat006" placeholder="请输入批号（cmt_xcbz008）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单位（cmt_xcbz009）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inat007">
              <a-input v-model="model.inat007" placeholder="请输入单位（cmt_xcbz009）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inat008">
              <a-input v-model="model.inat008" placeholder="请输入年度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="期别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inat009">
              <a-input v-model="model.inat009" placeholder="请输入期别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inat010">
              <a-input v-model="model.inat010" placeholder="请输入单价"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="期末结存数量（cmt_xcbz901）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inat015">
              <a-input v-model="model.inat015" placeholder="请输入期末结存数量（cmt_xcbz901）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerQty">
              <a-input v-model="model.customerQty" placeholder="请输入客户数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentQty">
              <a-input v-model="model.currentQty" placeholder="请输入当前数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结余数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remainder">
              <a-input v-model="model.remainder" placeholder="请输入结余数量"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ChHubForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ch/chHub/add",
          edit: "/ch/chHub/edit",
          queryById: "/ch/chHub/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>